package com.h.heal.mapper;

import com.h.heal.entity.Topic;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Mapper
@Component
public interface TopicMapper {
    @Select("SELECT * FROM `topic`")
    List<Topic> findAll();

    @Select("SELECT * FROM `topic` where topic_title=#{topic_title}")
    List<Topic> findByTopic_title(String topic_title);

    @Select("SELECT * FROM `topic` where topic_uid=#{topic_uid}")
    List<Topic> findByTopic_uid(String topic_uid);


    @Delete("delete from `topic` where topic_tid =#{topic_tid}")
    void deleteById(int id);


//    List<Topic> findBySearch(String topic_title, String topic_uid);


    @Insert("INSERT INTO `heal`.`topic` (`topic_uid`, `topic_title`, `topic_timestamp`, `topic_like`, `topic_maintext`) VALUES (#{topic_uid}, #{topic_title}, #{topic_timestamp},0, #{topic_maintext})")
    void create(Topic topic);

    @Select("SELECT * FROM `topic` where topic_tid=#{topic_tid}")
    Topic findById(int id);

    @Update("update topic set topic_title=#{topic_title},topic_maintext=#{topic_maintext} where topic_tid=#{topic_tid}")
    void edit(Topic topic);

    @Update("UPDATE topic SET topic_like=topic_like+1 WHERE topic_tid =#{topic_tid}")
    void like(@Param("topic_tid")String topic_tid);

    List<Topic> findBySearch(@Param("topic_title") String topic_title, @Param("topic_uid") String topic_uid);


    int count(String topic_title, String topic_uid);

    //分页查找
    List<Topic> findBySearchWithPage(String topic_title, String topic_uid, int startPageIndex, int pageSize);

}
